package com.yang.utils;

import com.yang.domain.entity.LoginUser;
import com.yang.enums.AppHttpCodeEnum;
import com.yang.exception.SystemException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author Admin
 */
public class SecurityUtils {

    public static LoginUser getLoginUser(){
        return (LoginUser) getAuthentication().getPrincipal();
    }

    public static Authentication getAuthentication(){
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static Long getUserId(){
        return getLoginUser().getUser().getId();
    }

    public static Boolean isAdmin(){
        Long userId = getLoginUser().getUser().getId();

        return userId != null && 1L == userId;

    }
}
